#!/bin/bash

# Copyright (C) Graphic Tribe. All rights reserved.

TotalSteps=1
while [[ $# -gt 0 ]] ; do
	case "$1" in
	-h | --help)
		;;
	-p | --periodic)
		TotalSteps=2; args=1 ;;
	-y | --yes)
		args=1 ;;
	esac
	shift
done

if [[ $args != 1 ]] ; then
	/usr/bin/open ./BWW2.rtf; exit
fi

if [[ `stat -f %p $0` != "100550" ]] ; then
	echo "Script is not properly protected."
	echo "Script mode is `stat -f %p $0` but should be 100550."
	exit
fi
if [[ `stat -f %u%g $0` != "080" ]] ; then
	echo "Script is not properly protected."
	echo "Script ownership is `stat -f %u:%g $0` but should be 0:80."
	exit
fi

echo -n "Post-reboot maintenance started on "; date '+%Y.%m.%d at %H:%M:%S.'; echo "---"; echo

echo "Step 1 of $TotalSteps: Checking syntax of property lists..."
plutil -s /Library/Preferences/*.plist ~/Library/Preferences/*.plist
find /Developer/Applications /Applications ~/Applications -iname '*.plist' -exec plutil -s {} \;
echo "Step 1 completed."; echo

if [[ $TotalSteps = 2 ]] ; then
	echo "Step 2 of $TotalSteps: Running the periodic scripts..."
	periodic daily weekly monthly
	echo "Step 2 completed."
fi

echo "---"; echo -n "Done. Post-reboot maintenance completed on "; date '+%Y.%m.%d %H:%M:%S.'; echo
